﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <a href="/">Back</a>
    <button type="button" name="login" id="login">点击按钮请求token,通过token获取题目</button>
    <div id="test"></div>
    <div id="title"></div>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script>
        $("#login").click(function () {
            $.ajax({
                url: "https://sso-qas.hi-p.com/connect/token",
                dataType: "json",
                type: "post",
                data: {
                    client_id: '074c448d-8786-414a-849f-d64ec9873da1',
                    client_secret: '074c448d-8786-414a-849f-d64ec9873da1',
                    grant_type: 'client_credentials',
                    scope: 'api1'
                },
                success: function (result) { //这里就是我出错的地方
                    console.log(result);
                    var html = "";
                    html += "<span>token：" + result.access_token + "</span>";
                    $("#test").html(html); //在html页面id=test的标签里显示html内容
                    $.ajax({
                        url: "https://surveyqas.hi-p.com/api/survey/getquestionnaire",
                        headers: {
                            'Authorization': 'Bearer ' + result.access_token,
                        },
                        dataType: "json",
                        type: "get",
                        data: {
                            'QuestionnaireName': '测试',
                        },
                        success: function (result) { //这里就是我出错的地方
                            console.log(result);
                            var html = "";
                            html += "<span>问卷题目：" + result.Name + "</span>";
                            $("#title").html(html); //在html页面id=test的标签里显示html内容
                        },
                        error: function (data) { }
                    })

                },
                error: function (data) {
                    alert("请求出错");
                    alert(data);
                }
            })
        })
    </script>

</body>

</html>